//
//  SSquedingVC.m
//  Hand-held_kitchen
//
//  Created by 张张烨 on 16/1/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SSquedingVC.h"
#import "ZongTouwenjian.pch"
#import "SSquedingCell.h"
#import "SSquedingMobel.h"
#import "SSErjiVc.h"
#import "HorViewController.h"
@interface SSquedingVC ()<UITableViewDataSource,UITableViewDelegate,pass111Delegate>
@property (nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)NSMutableArray *dataArr;
@property (nonatomic, retain)NSString *straa;
@property (nonatomic,retain)NSString *title1;
@end

@implementation SSquedingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self data];
    [self table];
//    SSquedingMobel *m = [[SSquedingMobel alloc]init];
//    m.searchText = self.str;
    
}
/**<  强制竖屏 */
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(void)table
{
    self.tableView = [[UITableView alloc]initWithFrame:Frame style:(UITableViewStylePlain)];
    
    _tableView.dataSource=self;
    _tableView.delegate =self;
    [_tableView registerClass:[SSquedingCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableView];
    [_tableView release];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  _dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SSquedingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    SSquedingMobel *m = _dataArr[indexPath.row];
    [cell.tupian sd_setImageWithURL:[NSURL URLWithString:m.image]];
//    cell.mingzi.text = m.title;
    cell.neirong.text = m.description1;
   
    self.straa = m.video;
    self.title1 = m.title;
    
    cell.deledate =self;
    
    ///高亮设置
    NSMutableAttributedString *attrituteString = [[NSMutableAttributedString alloc] initWithString:m.title];
    NSRange range = [m.title rangeOfString:self.str];
    [attrituteString setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],   NSFontAttributeName : [UIFont systemFontOfSize:20]} range:range];
    cell.mingzi.attributedText = attrituteString;
    
    
    
    
    
    
    cell.shijian.text = [NSString stringWithFormat:@"烹饪时间: %@",m.cooking_time];
    return cell;
    
}

- (void)tiaozhuan
{
    HorViewController *hoVC = [[HorViewController alloc] init];
    
    hoVC.str = self.straa;
    hoVC.title = self.title1;
    [self presentViewController:hoVC animated:YES completion:^{
        
    }];
}




-(void)data{
    
    NSString *urlStr = [self.str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:self.str]];
    
    
NSString *str =[NSString stringWithFormat:@"http://api.izhangchu.com/?methodName=SearchDishes&size=20&page=1&keyword=%@&version=4.3&",urlStr];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:str parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
    
} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    
    NSArray *arr = responseObject[@"data"][@"data"];
    self.dataArr = [SSquedingMobel modelHanderWithArray:arr];
    
    
    [_tableView reloadData];
    
    
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    
}];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SSErjiVc *dierye = [[SSErjiVc alloc]init];
    SSquedingMobel *m = _dataArr[indexPath.row];
    dierye.str = m.dishes_id;
    
    
    
    
    [self.navigationController pushViewController:dierye animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
